<?php
define("ROOT_PATH",realpath("./"));
$targetName=date("YmdHis");

$target_dir  = "/notes/";

$target_path = ROOT_PATH.$target_dir.$targetName.".jpg";

$subject=$_POST["subject"];
$content=$_POST["content"];
$userName=$_POST["UserName"];

if(move_uploaded_file($_FILES['note']['tmp_name'], $target_path)) {
	
	$dbh = new PDO('mysql:dbname=orb;host=localhost', 'root', '');
	
	$prep = $dbh->prepare('INSERT INTO Notes(noteid,ratedcount,point,filename,subject,content,username) VALUES(:noteid,:ratedcount,:point,:filename,:subject,:content,:username)');
	$prep->bindValue(':noteid',$targetName,PDO::PARAM_STR);
	$prep->bindValue(':ratedcount',0,PDO::PARAM_INT);
	$prep->bindValue(':point',0,PDO::PARAM_INT);
	$prep->bindValue(':filename',$targetName.".jpg",PDO::PARAM_STR);
	$prep->bindValue(':subject',$subject,PDO::PARAM_STR);
	$prep->bindValue(':content',$content,PDO::PARAM_STR);
	$prep->bindValue(':username',$userName,PDO::PARAM_STR);
	$prep->execute();
	
	header("Location: http://hacksteam-a.dnuts.jp/mypage.php");
	exit(0);
}else{
	echo "エラーが発生しました。";
}
?>